import cn.edu.hbsi.dao.BookDao;
import cn.edu.hbsi.domain.Book;
import cn.edu.hbsi.utils.GetSqlSessionUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Test;

public class testBook
{
    private SqlSession sqlSession = GetSqlSessionUtil.getSqlSession();
    private SqlSession sqlSession2 = GetSqlSessionUtil.getSqlSession();
    private SqlSession sqlSession3 = GetSqlSessionUtil.getSqlSession();

    private BookDao bookDao = sqlSession.getMapper(BookDao.class);
    private BookDao bookDao2 = sqlSession2.getMapper(BookDao.class);
    private BookDao bookDao3 = sqlSession3.getMapper(BookDao.class);

    @Test
    public void testSelectBookById(){
        Integer id = 1;

        Book book1 = bookDao.selectBookById(id);
        System.out.println(book1);
        Book book2 = bookDao.selectBookById(id);
        System.out.println(book2);

        Book book6 = bookDao.selectBookById(2);
        System.out.println(book6);
        Book book8 = bookDao.selectBookById(2);
        System.out.println(book8);

        Book book3 = new Book(1,"《Java》",45,"itheima");

        Integer updateBookCount = bookDao.updateBook(book3);
        System.out.println(updateBookCount);

        Book book4 = bookDao.selectBookById(id);
        System.out.println(book1);

        Book book5 = bookDao.selectBookById(id);
        System.out.println(book2);

        Book book7 = bookDao.selectBookById(2);
        System.out.println(book7);
        Book book9 = bookDao.selectBookById(2);
        System.out.println(book9);
    }

    @Test
    public void testUpdateBook(){
        Book book1 = bookDao.selectBookById(1);
        System.out.println(book1);
//        sqlSession.close();

        Book book2 = bookDao.selectBookById(1);
        System.out.println(book2);
        sqlSession.close();

//        Integer i = bookDao2.updateBook(new Book(1,"《Java》",45,"itheima"));
//        System.out.println(i);



        Book book3 = bookDao2.selectBookById(1);
        System.out.println(book3);
        Book book4 = bookDao2.selectBookById(1);
        System.out.println(book4);
        sqlSession2.close();

        Book book5 = bookDao3.selectBookById(1);
        System.out.println(book5);
        Book book6 = bookDao3.selectBookById(1);
        System.out.println(book6);
        sqlSession3.close();
    }

    @After
    public void destory(){
//        sqlSession.commit();
//        sqlSession.close();
    }
}